<template>
  <Body :body="schema.body" />
</template>
<script setup>
import { handleApi } from '../../common/api'
import { ref, getCurrentInstance } from 'vue'
import Body from '../../container/body/index.vue'
defineOptions({ name: 'ApiCom' })

const instance = getCurrentInstance()

const props = defineProps({
  schema: {
    type: Object,
    required: true
  }
})
const api = props.schema.api
const initDataFields = api.initDataFields || []
const lowCodeComponentData = ref({})
if (!initDataFields.length) {
  console.warn('没有initDataFields属性')
} else {
  for (const field of initDataFields) {
    lowCodeComponentData.value[field] = undefined
  }
}
handleApi(api, instance).then((data) => {
  if (!api.initDataFields) {
    console.warn('没有initDataFields属性')
  } else {
    for (const key in data) {
      lowCodeComponentData.value[key] = data
    }
  }
})
</script>
